package cn.newgrand.netcall.smackx.integration;

import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smackx.packet.OfflineMessageInfo;
import org.xmlpull.v1.XmlPullParser;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
 * @author SidneyRen E-mail:SidneyRen@hotmail.com
 * @version create time：2010-12-1 下午08:13:40
 * 类说明
 */
public class AppSysMes implements PacketExtension {
	/**
	 * Represents timestamp information about data stored for later delivery. A DelayInformation will 
	 * always includes the timestamp when the packet was originally sent and may include more 
	 * information such as the JID of the entity that originally sent the packet as well as the reason
	 * for the dealy.<p>
	 * 
	 * For more information see <a href="http://www.jabber.org/jeps/jep-0091.html">JEP-91</a>.
	 * 
	 * @author Gaston Dombiak
	 */

	    private String type;
	    private String reason;


	    /**
	     * Returns the JID of the entity that originally sent the packet or that delayed the 
	     * delivery of the packet or <tt>null</tt> if this information is not available.
	     * 
	     * @return the JID of the entity that originally sent the packet or that delayed the 
	     *         delivery of the packet.
	     */
	    public String getType() {
	        return type;
	    }

	    /**
	     * Sets the JID of the entity that originally sent the packet or that delayed the 
	     * delivery of the packet or <tt>null</tt> if this information is not available.
	     * 
	     * @param from the JID of the entity that originally sent the packet.
	     */
	    public void setType(String type) {
	        this.type = type;
	    }


	    /**
	     * Returns a natural-language description of the reason for the delay or <tt>null</tt> if 
	     * this information is not available.
	     * 
	     * @return a natural-language description of the reason for the delay or <tt>null</tt>.
	     */
	    public String getReason() {
	        return reason;
	    }

	    /**
	     * Sets a natural-language description of the reason for the delay or <tt>null</tt> if 
	     * this information is not available.
	     * 
	     * @param reason a natural-language description of the reason for the delay or <tt>null</tt>.
	     */
	    public void setReason(String reason) {
	        this.reason = reason;
	    }

	    public String getElementName() {
	        return "x";
	    }

	    public String getNamespace() {
	        return "jabber:x:appsys";
	    }

	    public String toXML() {
	        StringBuilder buf = new StringBuilder();
	        buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
	                "\"");
	        
	        if (type != null && type.length() > 0) {
	            buf.append(" type=\"").append(type).append("\"");
	        }
	        buf.append(">");
	        buf.append("</").append(getElementName()).append(">");
	        return buf.toString();
	    }

	
	 public static class Provider implements PacketExtensionProvider {

	        /**
	         * Creates a new Provider.
	         * ProviderManager requires that every PacketExtensionProvider has a public,
	         * no-argument constructor
	         */
	        public Provider() {
	        }

	        /**
	         * Parses a OfflineMessageInfo packet (extension sub-packet).
	         *
	         * @param parser the XML parser, positioned at the starting element of the extension.
	         * @return a PacketExtension.
	         * @throws Exception if a parsing error occurs.
	         */
	        public PacketExtension parseExtension(XmlPullParser parser)
	            throws Exception {
	            AppSysMes info = new AppSysMes();
	            info.setType(parser.getAttributeValue("","type"));
	            return info;
	        }

	    }

}
